package com.example.practice.activity;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.practice.R;


public class ylVideoPlayActivity extends AppCompatActivity {
    private VideoView yl_videoView;
    private MediaController yl_controller;
    private String yl_videoPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yl_video_play);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        yl_videoPath=getIntent().getStringExtra("videoPath");
        initView();
    }

    private void initView() {
        yl_videoView=findViewById(R.id.yl_videoView);
        yl_controller=new MediaController(this);
        yl_videoView.setMediaController(yl_controller);
        play();
    }

    private void play() {
        if(TextUtils.isEmpty(yl_videoPath)){
            Toast.makeText(this,"本地没有此视频,无法播放",Toast.LENGTH_SHORT).show();
            return;
        }
        String uri= "android.resource://"+getPackageName()+"/"+R.raw.video11;
        yl_videoView.setVideoPath(uri);
        yl_videoView.start();
    }
}